package com.jacky.flutter_screen_recording;

import com.jacky.crypto.*;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.List;

public class EvidShotBean {
    public String fileName;
    public String filePath;
    public String md5;
    public long time;
    public long fileSize;

    public static JSONArray transfor(List<EvidShotBean> list) {
        JSONArray array = new JSONArray();
        for(EvidShotBean bean : list) {
            JSONObject json = new JSONObject();
            try {
                json.put("fileSize", bean.fileSize);
                json.put("fileName", bean.fileName);
                json.put("md5", bean.md5);
                json.put("time", bean.time);
                array.put(json);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return array;
    }

    public static JSONObject transfor(File reportFile, String digest) {
        JSONObject reportInfo = new JSONObject();
        try {
            reportInfo.put("fileName", reportFile.getName());
            if("SHA-256".equals(digest)) {
                reportInfo.put("md5", EDA.SHA256.digest(reportFile));
            } else {
                reportInfo.put("md5", EDA.MD5.digest(reportFile));
            }
            reportInfo.put("fileSize", String.valueOf(reportFile.length()));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return reportInfo;
    }
}
